import { get, post } from '../ajax'
import { getAjaxBaseUrl } from '../handler'

import type { STORAGE_MODES } from '@/enum/modules/indicator'

const baseUrl = getAjaxBaseUrl('/electricity', '/energy')

/** 添加电价配置 */
export function addElectricityConfig(data: Record<string, any>) {
  return post<any>(`${baseUrl}/create`, data)
}

/** 更新电价配置 */
export function updateElectricityConfig(data: Record<string, any>) {
  return post<any>(`${baseUrl}/update`, data)
}

/** 删除电价配置 */
export function deleteElectricityConfig(time: string) {
  return post<any>(`${baseUrl}/delete/${time}`)
}

/** 查询电价配置 */
export function getElectricityConfig(time: string) {
  return get<any>(`${baseUrl}/list`, { time })
}

/** 分页查询电价配置 */
export function getElectricityConfigByPage(params: {
  pageNumber: number
  pageSize: number
  time: string
}) {
  return get<any>(`${baseUrl}/page`, params)
}

/** 检验某时间是否已经配置了电价 */
export function checkElectricityConfig(time: string) {
  return get<any>(`${baseUrl}/check`, {
    time,
  })
}

/** 获取饼图占比数据 */
export function getPieData(pointId: number, data: {
  timeType: STORAGE_MODES
  startTime: string
  endTime: string
}) {
  return get(
    `${baseUrl}/analyse/proportion/${pointId}`,
    data,
  )
}

/** 获取折线图趋势数据 */
export function getLinesData(pointId: number, data: {
  timeType: STORAGE_MODES
  startTime: string
  endTime: string
}) {
  return get(
    `${baseUrl}/analyse/${pointId}`,
    data,
  )
}
